<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>

<?php echo $layout_for_common;?>

<script type="text/javascript">
	$(document).ready(function(){
		
		//搜索
		$('.search').click(function(){
			$("#dialog-search").dialog("open");
			$("#dialog-search").find("form:eq(0)").submit(function(){
				var name = $('#search_name').val();
				var directory = $('#search_directory').val();
				var controller = $('#search_controller').val();
				var method = $('#search_method').val();
				var banned = $('[name=search_banned]').filter(":checked").val();

				location.href = '<?php echo admin_url('access/search');?>?name='+name+'&directory='+directory+'&controller='+controller+'&method='+method+'&banned='+banned;
			});
		});

		$( "#dialog-search" ).dialog({
			autoOpen: false,
			height: 290,
			width: 350,
			title: '搜索访问权限',
			position: ['center', 150]
		});

		//禁用状态改变
		$('.banned').click(function(){
			var obj = $(this);
			var id = $(this).attr('data-id');
			var banned = $(this).text().indexOf('是') == 0 ? 0 : 1;
			
			$.ajax({
				'type' : 'GET',
				'url' : '<?php echo admin_url('access/banned');?>',
				'data' : {ajax:'ajax', id:id, banned:banned},
				'success' : function (result){
					result = eval('('+result+')');
					if (result.code == 0)
					{
						obj.html(banned == 0 ? '<span class="green">否</span>' : '<span class="red">是</span>');
					}
					else
					{
						alert(result.msg);
					}
				}
			});
		});
		
	});
</script>

</head>
<body>
	<div id="wrap">

		<div class="nav">
			<a href="<?php echo admin_url('access/insert');?>" class="button">添加访问权限</a>
			<a href="javascript:;" class="search button">搜索</a>
		</div>

		<div class="tabs">
			<ul>
				<li><a href="#tabs-default">访问权限</a></li>
			</ul>
			<div id="tabs-default">
				<table class="list" cellspacing="0">
					<tr>
						<th width="100">ID</th>
						<th>名称</th>
						<th width="150">目录</th>
						<th width="100">控制器</th>
						<th width="100">方法</th>
						<th width="50">禁用</th>
						<th width="200">操作</th>
					</tr>
					<?php
						foreach ($list as $row)
						{
					?>
					<tr class="t_center">
						<td><?php echo $row['id'];?></td>
						<td><?php echo $row['name'];?></td>
						<td><?php echo $row['directory'];?></td>
						<td><?php echo $row['controller'];?></td>
						<td><?php echo $row['method'];?></td>
						<td><a href="javascript:;" title="点击改变" class="banned" data-id="<?php echo $row['id'];?>"><?php echo $row['banned'] == 1 ? '<span class="red">是</span>' : '<span class="green">否</span>';?></a></td>
						<td>
							<a href="<?php echo admin_url('access/update', array('id' => $row['id']));?>">修改</a>
							<a href="<?php echo admin_url('access/delete', array('id' => $row['id']));?>" onclick="return false;" class="delete" >删除</a>
						</td>
					</tr>
					<?php
						}
					?>
				</table>
			</div>
		</div>
		
		<div class="page">
			共条<?php echo $page->rows();?>记录
			<?php echo $page->first();?>
			<?php echo $page->index();?>
			<?php echo $page->last();?>
		</div>
		
	</div>

	<!-- 搜索表单 start -->
	<div id="dialog-search" style="display:none;">
		<form onsubmit="return false;">
			<table class="form">
				<tr>
					<td width="100"><label for="search_name">名称：</label></td>
					<td><input type="text" name="search_name" value="<?php echo get('name');?>" id="search_name" class="input" style="width:200px;" /></td>
				</tr>
				<tr>
					<td width="100"><label for="search_directory">目录：</label></td>
					<td><input type="text" name="search_directory" value="<?php echo get('directory');?>" id="search_directory" class="input" style="width:200px;" /></td>
				</tr>
				<tr>
					<td width="100"><label for="search_controller">控制器：</label></td>
					<td><input type="text" name="search_controller" value="<?php echo get('controller');?>" id="search_controller" class="input" style="width:200px;" /></td>
				</tr>
				<tr>
					<td width="100"><label for="search_method">方法：</label></td>
					<td><input type="text" name="search_method" value="<?php echo get('method');?>" id="search_method" class="input" style="width:200px;" /></td>
				</tr>
				<tr>
					<td width="100"><label for="search_banned">禁用状态：</label></td>
					<td>
						<input type="radio" name="search_banned" value="0" <?php if(get('banned') == 0) {?>checked="checked"<?php }?> id="search_banned_no" /> <label for="search_banned_no">未禁用</label>
						<input type="radio" name="search_banned" value="1" <?php if(get('banned') == 1) {?>checked="checked"<?php }?> id="search_banned_yes" /> <label for="search_banned_yes">已禁用</label>
					</td>
				</tr>
				<tr>
					<td colspan="2" class="t_center"><input type="submit" value="确定" class="button" /></td>
				</tr>
			</table>
		</form>
	</div>
	<!-- 搜索表单 end -->

</body>
</html>